home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / snpd1292.zip / MATCH.H < prev    next >
C/C++ Source or Header  |  1992-12-26  |  4KB  |  108 lines

  1. /*
  2.  EPSHeader
  3.  
  4.    File: match.h
  5.    Author: J. Kercheval
  6.    Created: Sat, 01/05/1991  22:27:18
  7. */
  8. /*
  9.  EPSRevision History
  10.  
  11.    J. Kercheval  Wed, 02/20/1991  22:28:37  Released to Public Domain
  12.    J. Kercheval  Sun, 03/10/1991  18:02:56  add is_valid_pattern
  13.    J. Kercheval  Sun, 03/10/1991  18:25:48  add error_type in is_valid_pattern
  14.    J. Kercheval  Sun, 03/10/1991  18:47:47  error return from matche()
  15.    J. Kercheval  Tue, 03/12/1991  22:24:49  Released as V1.1 to Public Domain
  16. */
  17.  
  18. /*
  19.    Wildcard Pattern Matching
  20. */
  21.  
  22. #ifndef BOOLEAN
  23. # define BOOLEAN int
  24. # define TRUE 1
  25. # define FALSE 0
  26. #endif
  27.  
  28. /* match defines */
  29. #define MATCH_PATTERN  6    /* bad pattern */
  30. #define MATCH_LITERAL  5    /* match failure on literal match */
  31. #define MATCH_RANGE    4    /* match failure on [..] construct */
  32. #define MATCH_ABORT    3    /* premature end of text string */
  33. #define MATCH_END      2    /* premature end of pattern string */
  34. #define MATCH_VALID    1    /* valid match */
  35.  
  36. /* pattern defines */
  37. #define PATTERN_VALID  0    /* valid pattern */
  38. #define PATTERN_ESC   -1    /* literal escape at end of pattern */
  39. #define PATTERN_RANGE -2    /* malformed range in [..] construct */
  40. #define PATTERN_CLOSE -3    /* no end bracket in [..] construct */
  41. #define PATTERN_EMPTY -4    /* [..] contstruct is empty */
  42.  
  43. /*----------------------------------------------------------------------------
  44. *
  45. *  Match the pattern PATTERN against the string TEXT;
  46. *
  47. *       match() returns TRUE if pattern matches, FALSE otherwise.
  48. *       matche() returns MATCH_VALID if pattern matches, or an errorcode
  49. *           as follows otherwise:
  50. *
  51. *            MATCH_PATTERN  - bad pattern
  52. *            MATCH_LITERAL  - match failure on literal mismatch
  53. *            MATCH_RANGE    - match failure on [..] construct
  54. *            MATCH_ABORT    - premature end of text string
  55. *            MATCH_END      - premature end of pattern string
  56. *            MATCH_VALID    - valid match
  57. *
  58. *
  59. *  A match means the entire string TEXT is used up in matching.
  60. *
  61. *  In the pattern string:
  62. *       `*' matches any sequence of characters (zero or more)
  63. *       `?' matches any character
  64. *       [SET] matches any character in the specified set,
  65. *       [!SET] or [^SET] matches any character not in the specified set.
  66. *
  67. *  A set is composed of characters or ranges; a range looks like
  68. *  character hyphen character (as in 0-9 or A-Z).  [0-9a-zA-Z_] is the
  69. *  minimal set of characters allowed in the [..] pattern construct.
  70. *  Other characters are allowed (ie. 8 bit characters) if your system
  71. *  will support them.
  72. *
  73. *  To suppress the special syntactic significance of any of `[]*?!^-\',
  74. *  and match the character exactly, precede it with a `\'.
  75. *
  76. ----------------------------------------------------------------------------*/
  77.  
  78. BOOLEAN match (char *pattern, char *text);
  79.  
  80. int     matche(register char *pattern, register char *text);
  81.  
  82. /*----------------------------------------------------------------------------
  83. *
  84. * Return TRUE if PATTERN has any special wildcard characters
  85. *
  86. ----------------------------------------------------------------------------*/
  87.  
  88. BOOLEAN is_pattern (char *pattern);
  89.  
  90. /*----------------------------------------------------------------------------
  91. *
  92. * Return TRUE if PATTERN has is a well formed regular expression according
  93. * to the above syntax
  94. *
  95. * error_type is a return code based on the type of pattern error.  Zero is
  96. * returned in error_type if the pattern is a valid one.  error_type return
  97. * values are as follows:
  98. *
  99. *   PATTERN_VALID - pattern is well formed
  100. *   PATTERN_ESC   - pattern has invalid escape ('\' at end of pattern)
  101. *   PATTERN_RANGE - [..] construct has a no end range in a '-' pair (ie [a-])
  102. *   PATTERN_CLOSE - [..] construct has no end bracket (ie [abc-g )
  103. *   PATTERN_EMPTY - [..] construct is empty (ie [])
  104. *
  105. ----------------------------------------------------------------------------*/
  106.  
  107. BOOLEAN is_valid_pattern (char *pattern, int *error_type);
  108.